package com.zhht.checkcop.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhbc.framework.support.Result;
import com.zhht.checkcop.check.vo.AppVersion;
import com.zhht.checkcop.check.vo.ClassifyVO;
import com.zhht.checkcop.service.AppVersionService;
import com.zhht.checkcop.service.ClassifyService;

@Controller
public class AppVersionCotroller {

	@Autowired
	private AppVersionService AppVersionService;
	@Autowired
	private ClassifyService classifyService;
	
	private List<ClassifyVO> classifyLists;
	
	private final static Logger log = Logger.getLogger(AppVersionCotroller.class);

	@RequestMapping(value = "/bookapp/check_version", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String check_version(@RequestParam String param, HttpServletRequest request, HttpServletResponse re) {
		Result r = new Result();
		try {
			log.info("请求：/bookapp/check_version方法");
			List<AppVersion> AppVersion =AppVersionService.queryList(null, 0, 0);
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("AppVersion", AppVersion.get(0));
			r.setData(map);
		} catch (Exception e) {
			log.info(e.toString());
			return r.failure("请求失败");
		}
		return r.success();
	}
	@RequestMapping(value = "/bookapp/category_list", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String category_list(@RequestParam String param, HttpServletRequest request, HttpServletResponse re) {
		Result r = new Result();
		try {
			log.info("请求：/bookapp/category_list方法");
			if(null == classifyLists){
				classifyLists = classifyService.getClassifyList(1);
			}
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("classifyList", classifyLists);
			r.setData(map);
		} catch (Exception e) {
			log.info(e.toString());
			return r.failure("请求失败");
		}
		return r.success();
	}
	
}
